package com.my.ribbon.predicate;

import com.alibaba.cloud.nacos.ribbon.NacosServer;
import com.netflix.loadbalancer.AbstractServerPredicate;
import com.netflix.loadbalancer.PredicateKey;
import org.springframework.lang.Nullable;

/**
 * @author timo 2021/3/23
 */
public abstract class DiscoveryEnabledPredicate extends AbstractServerPredicate {
    public DiscoveryEnabledPredicate() {
    }

    @Override
    public boolean apply(@Nullable PredicateKey input) {
        return input != null && input.getServer() instanceof NacosServer && this.apply((NacosServer)input.getServer());
    }

    protected abstract boolean apply(NacosServer server);
}
